package com.lu.dao;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import com.lu.entity.Demo;

public class UserDao extends BaseDao{
	ResultSet rs=null;
	public List<Demo> getDemo(int page,int limit) {
		page=(page-1)*10;
		String sql="select * from demo limit ?,?";
		List<Demo> lDemos=new ArrayList<Demo>();
		rs=query(sql,page,limit);
		try {
			while(rs.next()) {
				Demo demo=new Demo();
				demo.setId(rs.getInt("id"));
				demo.setUsername(rs.getString("username"));
				demo.setSex(rs.getString("sex"));
				demo.setCity(rs.getString("city"));
				demo.setSign(rs.getString("sign"));
				demo.setExperience(rs.getString("experience"));
				demo.setLogins(rs.getString("logins"));
				demo.setWealth(rs.getString("wealth"));
				demo.setClassify(rs.getString("classify"));
				demo.setScore(rs.getInt("score"));
				lDemos.add(demo);
			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}finally {
			closeConnection();
		}
		return lDemos;
	}
	public int deleteData(int id) {
		String sql="delete from demo where id=? ";
		int count=0;
		count=update(sql, id);
		return count;
	}
	public int getCount() {
		String sql="select count(*) as count from demo";
		int count=0;
		rs=query(sql);
		try {
			while(rs.next()) {
				count=rs.getInt("count");
			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}finally {
			closeConnection();
		}
		return count;
	}
}
